var e = require("../../utils/config.js");

Page({
    data: {
        name: "",
        mobile: "",
        serviceProviderName: "",
        serviceProviderList: [],
        isShowDownArrow: !1,
        isAuthentication: !1,
        avatarUrl: ""
    },
    onLoad: function(e) {
        wx.getStorageSync("userId") || wx.navigateTo({
            url: "../login/login"
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = this, o = wx.getStorageSync("userInfo");
        o ? t.setData({
            avatarUrl: o.avatarUrl
        }) : t.setData({
            avatarUrl: ""
        });
        var a = wx.getStorageSync("userId");
        a ? wx.request({
            url: e.urlList.API_USER_GET_USER,
            method: "GET",
            data: {
                id: a
            },
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                if (200 == e.data.status) {
                    var o = e.data.data;
                    wx.setStorage({
                        key: "serviceProviders",
                        data: o.serviceProviders
                    }), t.setData({
                        name: o.name,
                        mobile: o.mobile,
                        serviceProviderList: o.serviceProviders,
                        isAuthentication: o.isAuthentication
                    }), o.serviceProviders.length > 0 && wx.getStorage({
                        key: "serviceProviderName",
                        success: function(e) {
                            t.setData({
                                serviceProviderName: e.data
                            });
                        },
                        fail: function() {
                            t.setData({
                                serviceProviderName: o.serviceProviders[0].name
                            }), wx.setStorage({
                                key: "serviceProviderName",
                                data: o.serviceProviders[0].name
                            }), wx.setStorage({
                                key: "serviceProviderId",
                                data: o.serviceProviders[0].id
                            });
                        }
                    }), o.serviceProviders.length > 1 ? t.setData({
                        isShowDownArrow: !0
                    }) : t.setData({
                        isShowDownArrow: !1
                    });
                } else wx.showToast({
                    title: e.data.message,
                    icon: "none"
                });
            }
        }) : t.setData({
            name: "",
            mobile: "",
            serviceProviderList: "",
            isAuthentication: !1
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    selectServiceProviderList: function() {
        if (wx.getStorageSync("userId")) {
            for (var e = this, t = [], o = 0; o < e.data.serviceProviderList.length; o++) t.push(e.data.serviceProviderList[o].name);
            wx.showActionSheet({
                itemList: t,
                success: function(t) {
                    console.log(t.tapIndex), e.setData({
                        serviceProviderName: e.data.serviceProviderList[t.tapIndex].name
                    }), wx.setStorage({
                        key: "serviceProviderName",
                        data: e.data.serviceProviderList[t.tapIndex].name
                    }), wx.setStorage({
                        key: "serviceProviderId",
                        data: e.data.serviceProviderList[t.tapIndex].id
                    });
                },
                fail: function(e) {
                    console.log(e.errMsg);
                }
            });
        } else wx.navigateTo({
            url: "../login/login"
        });
    },
    goToUpdateUserInfo: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "updateUserInfo"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToSignIn: function() {
        if (wx.getStorageSync("userId")) {
            if (!wx.getStorageSync("serviceProviderId")) return void wx.showToast({
                title: "无服务商归属，不能进行签到",
                icon: "none"
            });
            wx.navigateTo({
                url: "signIn"
            });
        } else wx.navigateTo({
            url: "../login/login"
        });
    },
    goToContract: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "contractList"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToFeedBack: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "feedBack"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToSetting: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "setting"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToRealNameAuthentication: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "realNameAuthentication"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToLogin: function() {
        wx.getStorageSync("userId") || wx.navigateTo({
            url: "../login/login"
        });
    },
    goToWorkReport: function() {
        var t = wx.getStorageSync("userId");
        if (t) {
            var o = wx.getStorageSync("serviceProviderId");
            if (!o) return void wx.showToast({
                title: "无服务商归属，不能进行工作汇报",
                icon: "none"
            });
            wx.showLoading({
                mask: !0
            }), wx.request({
                url: e.urlList.API_USER_CHECK_IS_AUTHENTICATION_AND_USER_INFO,
                method: "GET",
                data: {
                    userId: t,
                    serviceProviderId: o
                },
                success: function(e) {
                    wx.hideLoading(), 200 == e.data.status ? wx.navigateTo({
                        url: "../work/formSettingList"
                    }) : 415 == e.data.status ? wx.showModal({
                        title: "系统提示",
                        content: e.data.message,
                        cancelText: "下次再说",
                        confirmText: "立即完善",
                        success: function(e) {
                            e.confirm && wx.navigateTo({
                                url: "/pages/my/editBank"
                            });
                        }
                    }) : 416 == e.data.status ? wx.showModal({
                        title: "系统提示",
                        content: e.data.message,
                        cancelText: "下次再说",
                        confirmText: "实名认证",
                        success: function(e) {
                            e.confirm && wx.navigateTo({
                                url: "/pages/my/realNameAuthentication"
                            });
                        }
                    }) : wx.showToast({
                        title: e.data.message,
                        icon: "none"
                    });
                }
            });
        } else wx.navigateTo({
            url: "../login/login"
        });
    },
    goToIssue: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "issueList"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToFavorite: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "myFavoriteList"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    },
    goToRecordWorkTime: function() {
        var e = this;
        wx.getStorageSync("userId") ? e.data.isAuthentication ? wx.navigateTo({
            url: "recordWorkTime"
        }) : wx.showModal({
            title: "系统提示",
            content: "尚未实名认证，是否立即实名认证？",
            cancelText: "下次再说",
            confirmText: "实名认证",
            success: function(e) {
                e.confirm && wx.navigateTo({
                    url: "/pages/my/realNameAuthentication"
                });
            }
        }) : wx.navigateTo({
            url: "../login/login"
        });
    }
});